package com.esoon.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @ClassName ResultBody
 * @Description TODO
 * @Author 2020/10/10 16:40
 * @Version 1.0
 **/
@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultBody implements Serializable {
    private static final long serialVersionUID = 1L;

    private static final ObjectMapper MAPPER = new ObjectMapper();

    private Integer code;
    private String msg;
    private Object data;

    public static ResultBody success(Object data){
        return new ResultBody(data);
    }
    public static ResultBody success(){
        return new ResultBody(null);
    }
    public ResultBody(Object data){
        this.code = 200;
        this.msg = "请求成功";
        this.data = data;
    }

    public ResultBody(Integer code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultBody build(Integer code, String msg, Object data){
        return new ResultBody(code,msg,data);
    }

    public static ResultBody build(Integer code, String msg){
        return new ResultBody(code,msg,null);
    }

    public ResultBody(){

    }
}
